package com.beerq.view;

import android.graphics.drawable.AnimationDrawable;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.widget.ImageView;

import com.beerq.R;
import com.beerq.util.Constants;
import com.beerq.util.LogX;
import com.beerq.util.WebViewUtil;

import static com.beerq.util.Constants.userInfo;

public class WebViewActivity extends BaseActivity {

    private WebView mWebView;

    private View mViewHide;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if("1".equals(getIntent().getStringExtra("barType"))){
            statusBarType=1;
        }

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_product_detail);
        initView();

        ImageView img_loading=(ImageView)findViewById(R.id.img_loading) ;

        AnimationDrawable animationDrawable1 = (AnimationDrawable) img_loading.getDrawable();
        animationDrawable1.start();

    }

    protected void initView(){
        mWebView=(WebView)findViewById(R.id.webview);
        WebViewUtil.initWebView(this,mWebView);

        ProductJsManager productJsManager=new ProductJsManager(this,mWebView);
        mWebView.addJavascriptInterface(productJsManager, "android");




        String url=getIntent().getStringExtra("url");

        LogX.d("WebViewActivity",url);

        mWebView.loadUrl(getIntent().getStringExtra("url"));



        mViewHide=findViewById(R.id.rel_hide);

        mWebView.setWebChromeClient(new WebChromeClient() {
            @Override
            public void onProgressChanged(WebView view, int newProgress) {


                if (newProgress> 30) {

                    mViewHide.setVisibility(View.GONE);

//                    bar.setVisibility(View.GONE);
//                    handler.removeCallbacks(runnable);
                } else {
//                    if(count==0){
//                        handler.postDelayed(runnable,20000);
//                        count = count+1;
//                    }
//                    if (View.GONE == bar.getVisibility()) {
//                        bar.setVisibility(View.VISIBLE);
//                    }
//                    bar.setProgress(newProgress);
                }
                super.onProgressChanged(view, newProgress);
            }

        });

    }

}
